#!/usr/bin/env bash
# Copyright (c) 2021 The Toltec Contributors
# SPDX-License-Identifier: MIT

pkgnames=(netsurf)
pkgdesc="Lightweight web browser"
url=https://github.com/alex0809/netsurf-reMarkable
pkgver=0.4.0-3
timestamp=2021-05-31T11:15+00:00
maintainer="Alex Friesenhahn <rm-dev@alexfriesenhahn.de>"
archs=(rmall)
license=GPL-2.0-or-later
section="readers"
makedepends=(
    build:automake
    build:bison
    build:flex
    build:git
    build:gperf
    build:libpng-dev
    build:libtool
)
installdepends=(
    display
    dejavu-fonts-ttf-DejaVuSans
    dejavu-fonts-ttf-DejaVuSans-Bold
    dejavu-fonts-ttf-DejaVuSans-BoldOblique
    dejavu-fonts-ttf-DejaVuSans-Oblique
    dejavu-fonts-ttf-DejaVuSerif
    dejavu-fonts-ttf-DejaVuSerif-Bold
    dejavu-fonts-ttf-DejaVuSerif-Italic
    dejavu-fonts-ttf-DejaVuSansMono
    dejavu-fonts-ttf-DejaVuSansMono-Bold
)
image=base:v2.1
flags=(patch_rm2fb)

source=(
    https://github.com/alex0809/netsurf-reMarkable/archive/refs/tags/v0.4.tar.gz
    netsurf.draft
)
sha256sums=(
    a688ffc634fbbab463f92153b048e643fa6a5a1f92c492ff2005079a73a8de90
    SKIP
)

build() {
    ln -s /usr/bin/which /bin
    scripts/install_dependencies.sh
    TARGET_WORKSPACE=$(pwd)/build scripts/build.sh
}

package() {
    # Netsurf binary
    install -d "$pkgdir"/opt/bin
    install -D -m 755 "$srcdir"/build/netsurf/nsfb "$pkgdir"/opt/bin/netsurf

    # Draft launcher file
    install -d "$pkgdir"/opt/etc/draft
    install -D -m 644 "$srcdir"/netsurf.draft "$pkgdir"/opt/etc/draft/

    # Resources
    install -d "$pkgdir"/opt/usr/share/netsurf
    resdir="$srcdir"/build/netsurf/frontends/framebuffer/res
    install -D -m 644 -t "$pkgdir"/opt/usr/share/netsurf/ \
        "$resdir"/adblock.css \
        "$resdir"/default.css \
        "$resdir"/quirks.css \
        "$resdir"/internal.css \
        "$resdir"/Messages \
        "$resdir"/credits.html \
        "$resdir"/licence.html \
        "$resdir"/welcome.html \
        "$resdir"/welcome-netsurf.html \
        "$resdir"/netsurf.png

    # Default Choices file
    install -D -m 644 "$srcdir"/example/Choices "$pkgdir"/opt/usr/share/netsurf/Choices
}
